package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.property.Property;
import com.yanqu.road.utils.property.PropertyHelper;
import io.netty.channel.ChannelHandlerContext;


@Cmd(code = Protocol.S_BEAUTY_ESCORT_QUIT_UNION_SETTLEMENT_REWARD_FROM_CROSS, desc = "退出商会自动结算的奖励")
public class BeautyEscortAutoSettlementCmdFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        BeautyEscortProto.CrossBeautyEscortNotifyQuitUnionRespMsg reqMsg = BeautyEscortProto.CrossBeautyEscortNotifyQuitUnionRespMsg.parseFrom(packet.getBytes());
        long userId = reqMsg.getUserId();
        String unionUid = reqMsg.getUnionUid();
        for (BeautyEscortProto.CrossBeautyEscortSettlementRewardTemp rewardTemp : reqMsg.getRewardList()) {
            Property property = PropertyHelper.parseStringToProperty(rewardTemp.getReward());
            if(rewardTemp.hasEventReward()){
                property.addProperty(PropertyHelper.parseStringToProperty(rewardTemp.getEventReward()));
            }
            UserInfo userInfo = UserMgr.getUserInfo(userId);
            String title = MultipleLanguageMgr.getContent(MailManager.BEAUTY_ESCORT_QUIT_UNION_AUTO_SETTLEMENT_REWARD_TITLE, userInfo.getLanguage());
            String content = MultipleLanguageMgr.getContent(MailManager.BEAUTY_ESCORT_QUIT_UNION_AUTO_SETTLEMENT_REWARD_CONTENT, userInfo.getLanguage());
            MailManager.sendMail(userId, eMailType.DAILY.getValue(), PropertyHelper.parsePropertyToString(property), content, title);
        }

    }
}
